<?php
declare (strict_types=1);

namespace app\command;

use app\api\service\CommonService;
use app\common\model\WaterModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class SendDingMessage extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('send_text_message')
            ->setDescription('定时任务-定时提醒用户喝水');
    }

    protected function execute(Input $input, Output $output)
    {
        $h = (int)date('H',time());
        switch ($h){
            case 9:
            case 11:
            case 13:
            case 15:
            case 17:
            case 19:
            case 20:
            case 21:
                $this->sendMessageData();
                break;
            default:
                echo '暂未到时间';
        }

    }

    public function sendMessageData()
    {
        $water = new WaterModel();
        $comm = new CommonService();
        $ret = $water->where('type',1)->select()->toArray();
        if(!$ret){
            echo '暂无提醒人员';exit();
        }
        foreach ($ret as $v){
            $data = [
                "event" => "SendTextMsg",
                "robot_wxid" => $v['robot_id'],
                "to_wxid" => $v['wx_id'],
                "member_wxid" => '',
                "member_name" => '',
                "group_wxid" => '',
                "msg" => "叮～\n 小助手提醒您\n 喝水时间到了~\n 每天8杯水 健康每一天～",
            ];
            $comm->sendSGHttp($comm->API_URL, $data);
        }

    }
}
